myApp.controller('orderListController',function($scope,toaster,$uibModal,$filter,$state,$log,$serOrder){
    var ctrl = this;
    ctrl.vm = {
        data:{},
        search:{
            id:'',
            startTime:'',
            endTime:'',
            state:'',
            startStamp:'',
            endStamp:''
        },
        changeTimeS:function(){
              ctrl.vm.search.startStamp = Date.parse(ctrl.vm.search.startTime);
              ctrl.vm.search.endStamp = Date.parse(ctrl.vm.search.endTime);
        },
        changeTimeE:function(){
            ctrl.vm.search.startStamp = Date.parse(ctrl.vm.search.startTime);
            ctrl.vm.search.endStamp = Date.parse(ctrl.vm.search.endTime);
        },
        searchFn:function(){
            vm.init();
        },
        reset:function(){
            ctrl.vm.search.id='';
            ctrl.vm.search.startTime='';
            ctrl.vm.search.endTime='';
            ctrl.vm.search.state='';
            vm.init();
        }
    };
    $scope.vm={
        page:{}
    };
    /*跳转页面*/
    $scope.pageChanged = function() {
        vm.init($scope.vm.page.current_page)
    };
    /*每页显示数量显示*/
    $scope.placement = {
        options: [5,10,20,50],
        pageSize:5,
        selected: 10,
        changeFn:function(){
            vm.init(0)
        }
    };
    $scope.model = {
        open: function (id) {
            $scope.model.info = id;
            var modalInstance = $uibModal.open({
                templateUrl: 'itemModalContent.html',
                controller: 'itemModalContentCtrl',
                windowClass: 'adminOpen',
                resolve: {
                    info: function () {
                        return $scope.model.info;
                    }
                }
            });
            modalInstance.result.then(function (res) {
                if (res) {
                   vm.init();
                }
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        }
    };
    var vm ={
        init:function(page){
            var startT = $filter('date')(ctrl.vm.search.startTime,'yyyy-MM-dd 00:00:00');
            var endT = $filter('date')(ctrl.vm.search.endTime,'yyyy-MM-dd 23:59:59');
            $serOrder.getList({
                page:page||1,
                size:$scope.placement.selected,
                id:ctrl.vm.search.id||'',
                status:ctrl.vm.search.state||'',
                start_at:startT||'',
                end_at:endT||''
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data = res.data;
                   $scope.vm.page = res.addtion_data;
                }else{
                    ctrl.vm.data ="";
                    toaster.info('提示',res.message);
                }
            })
        }
    };
    vm.init();
    $scope.open = function() {
        $scope.popup.opened = true;
    };
    $scope.popup = {
        opened: false
    };
    $scope.open1 = function() {
        $scope.popup1.opened = true;
    };
    $scope.popup1 = {
        opened: false
    };
});

myApp.controller('itemModalContentCtrl', function($scope, $uibModalInstance, info,$serOrder, toaster) {
    $scope.data = {

    };
    function init(){
        $serOrder.getIt({
            id:info
        }).then(function(res){
             if(res.code==1){
                 $scope.data = res.data;
                 console.log(123,$scope.data);
             }else{
                 toaster.info('提示',res.message);
             }
        })
    };
    init();
    $scope.ok = function () {
        $uibModalInstance.close($scope.info);
    };

    $scope.cancel = function () {
        $uibModalInstance.dismiss(0);
    };
});